package net.mycrub.bitwise.ocr.reading;

import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;

public class Sampler {

    private ISampleFilter filter;

    public double[] sample(BufferedImage img) {
        int w = img.getWidth();
        int h = img.getHeight();
        int[] pix = new int[w * h];
        PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pix, 0, w);
        try {
            pg.grabPixels();
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }

        return getFilter().filter(pix);
    }

    public ISampleFilter getFilter() {
        if (filter == null) {
            filter = new DefaultSampleFilter(true);
        }
        return filter;
    }

}
